package com.moxiu.browser.util;

import com.cmcm.newssdk.entity.Article;
import com.moxiu.browser.BrowserActivity;
import com.moxiu.browser.IntentHandler;
import com.moxiu.browser.Tab;
import com.moxiu.browser.homepage.HomePagePara;
import com.moxiu.browser.provider.Browser;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;

public class InnerJumpToBrowserUtil {

	public final static String APP_ID_FOR_INNER_INCRESS_VALUE = "com.moxiu.browser.id";

	public static void jumpTowBrowser(Context context, String url, String tag) {
		try {
			jumpTowBrowserWithHomePara(context, url, tag, null, false);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void jumpTowBrowserWithHomePara(Context context, String url,
			String tag, Article article, boolean hasGdt) {
		try {
			// Log.i("kevint", "xxxxx==jumpTowBrowser=tag="+tag);
			Intent intent = new Intent(Intent.ACTION_VIEW);
			intent.setClassName(context, BrowserActivity.class.getName());
			intent.setData(Uri.parse(url));// ("http://sina.cn/"));
			intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
			intent.putExtra(Browser.EXTRA_APPLICATION_ID,
					APP_ID_FOR_INNER_INCRESS_VALUE);

			intent.putExtra(BrowserActivity.FROM_TAG, "from-" + tag);

			// Log.i("kevint", "ReportReadTime===article="+article);
			if (article != null) {
				// Log.i("kevint",
				// "ReportReadTime==111111111111=article="+article);
				intent.putExtra(IntentHandler.HOME_PAGE_SEARCH_PARA,
						new HomePagePara(hasGdt ? Tab.TAG_FROM_HOME_PAGE_GDT
								: "", article));

			}
			context.startActivity(intent);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void jumpTowBrowserWithHomePara(Context context, String url,
			String tag, String gdtH5) {
		try {
			// Log.i("kevint", "xxxxx==jumpTowBrowser=tag="+tag);
			Intent intent = new Intent(Intent.ACTION_VIEW);
			intent.setClassName(context, BrowserActivity.class.getName());
			intent.setData(Uri.parse(url));// ("http://sina.cn/"));
			intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
			intent.putExtra(Browser.EXTRA_APPLICATION_ID,
					APP_ID_FOR_INNER_INCRESS_VALUE);

			intent.putExtra(BrowserActivity.FROM_TAG, "from-" + tag);

			// Log.i("kevint", "ReportReadTime===article="+article);
			if (gdtH5.equals("gdtH5")) {
				// Log.i("kevint",
				// "ReportReadTime==111111111111=article="+article);
				intent.putExtra(IntentHandler.HOME_PAGE_SEARCH_PARA,
						Tab.TAG_FROM_SITES_TOUTIAO);

			}
			context.startActivity(intent);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
